<?php

/* ugly custom formatter for radio buttons in the form */
function formatter_radio($widget, $inputs) {
    $rows = array();
    foreach ($inputs as $input) {
        $input['label'] = str_replace('label', 'span', $input['label']);
        $rows[] = $widget->renderContentTag('td', $input['input'] . $widget->getOption('label_separator') . $input['label'], array('align' => 'left'));
    }

    return !$rows ? '' : '<table style="border-spacing: 10px 0px">' . $widget->renderContentTag('tr', implode($widget->getOption('separator'), $rows), array('class' => $widget->getOption('class'))) . '</table>';
}

function formatter_radio2($widget, $inputs) {
    $rows = array();
    foreach ($inputs as $input) {
        $input['label'] = str_replace('label', 'span', $input['label']);
        $rows[] = $widget->renderContentTag('span', $input['input'] . $widget->getOption('label_separator') . $input['label'], array('align' => 'left'));
    }

    return !$rows ? '' : '<table style="border-spacing: 10px 0px"><tr><td>' . $widget->renderContentTag('span', implode(' ', $rows), array('class' => $widget->getOption('class'))) . '</td></tr></table>';
}

function render_date($date) {

    return format_date($date, 'p');
}

function get_hour_minute($date) {
    $info = date_parse($date);

    return get_hour($date) . ':' . get_minute($date);
}

function get_hour($date) {
    $info = date_parse($date);

    if (1 == strlen($info['hour']))
        $info['hour'] = '0' . $info['hour'];

    return $info['hour'];
}

function get_minute($date) {
    $info = date_parse($date);
    if ('0' == $info['minute'])
        $info['minute'] = '00';

    if (1 == strlen($info['minute']))
        $info['minute'] = '0' . $info['minute'];

    return $info['minute'];
}

function decideTodayOrTomorrow($date) {
    if (Util::isToday($date)) 
        return __('Today - ');
    if (Util::isTomorrow($date))
        return __('Tomorrow - ');

    return null;
}

function decideSpecialDate($date, $special_dates = array()) {
    foreach ($special_dates as $special_date)
        if ($date == $special_date['date'])
            return ' - ' . $special_date['description'];

    return null;
}

function render_select($data, $selected_value, $html_id) {
    ?>
    <select id="<?php echo $html_id ?>" style="font-size: 18px;">
        <?php foreach ($data as $data_key => $data_value): ?>
        <option value="<?php echo $data_key ?>"
                <?php if ($data_key == $selected_value) echo ' selected="selected"' ?>>
            <?php echo $data_value ?>
        </option>
        <?php endforeach ?>
    </select>
    <?php
}